﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Controls;
using Silvermoon.Controls.Classes;
using System.Drawing;
using Silvermoon.Shapes;

namespace Testing
{

    public class GradientControl : AnimationGrid
    {
        private GradientShape top, bottom;


        public GradientControl()
            : base()
        {

            top = new GradientShape { Orientation = ColorOrientation.Vertical, StartColor = Color.Black, EndColor = Color.DarkBlue };
            bottom = new GradientShape { Orientation = ColorOrientation.Vertical, EndColor = Color.Black, StartColor = Color.DarkBlue };
            Shapes.AddRange(top, bottom);
            Margin = Margin.Zero;
        }

        public GradientControl(Color color)
            : this()
        {
            GradientColor = color;
        }

        public Color TopColor
        {
            get { return top.StartColor; }
            set
            {
                if (TopColor != value)
                {
                    top.StartColor = value;
                    Invalidate(InvalidationFlag.Appearance);
                }
            }
        }

        public Color BottomColor
        {
            get { return bottom.EndColor; }
            set
            {
                if (BottomColor != value)
                {
                    bottom.EndColor = value;
                    Invalidate(InvalidationFlag.Appearance);
                }
            }
        }


        public Color GradientColor
        {
            get { return top.EndColor; }
            set
            {
                if (GradientColor != value)
                {
                    top.EndColor = value;
                    bottom.StartColor = value;
                    Invalidate(InvalidationFlag.Appearance);
                }
            }
        }

        protected override void OnLayout()
        {
            if (CheckFlag(InvalidationFlag.Size))
            {
                int h2 = Height / 2;
                top.Bounds = new Rectangle(0, 0, Width, h2);
                bottom.Bounds = new Rectangle(0, h2, Width, Height - h2);
            }
            base.OnLayout();
        }
    }
}
